package com.axend.aerosense.base.viewmodel;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.axend.aerosense.base.impl.ISimpleAction;

import java.lang.reflect.InvocationTargetException;

public class SimpleModelFactroy<T> implements ViewModelProvider.Factory {
    private ISimpleAction<T> simpleActionImpl;

    public SimpleModelFactroy(ISimpleAction<T> simpleActionImpl) {
        this.simpleActionImpl = simpleActionImpl;
    }

    @NonNull
    @Override
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        try {
            return modelClass.getConstructor(ISimpleAction.class).newInstance(simpleActionImpl);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
